<!DOCTYPE html>
<html lang="en">
<head>
    <title>AVDC</title>
</head>
<body>
<div class="page type-interior pluginConfigurationPage"
     data-require="emby-input,emby-button,emby-select,emby-checkbox"
     data-role="page"
     id="avdcConfigurationPage">
    <div data-role="content">
        <div class="content-primary">
            <h1>AVDC</h1>
            <p>Provides additional metadata for adult videos by AVDC.</p>
            <form id="avdcConfigForm">
                <div class="inputContainer">
                    <label class="inputeLabel inputLabelUnfocused" for="Server">Server</label>
                    <input id="Server" is="emby-input" name="Server" required type="text"/>
                    <div class="fieldDescription">URL for Backend AVDC Server.</div>
                </div>
                <div class="inputContainer">
                    <label class="inputeLabel inputLabelUnfocused" for="Token">Token</label>
                    <input id="Token" is="emby-input" name="Token" type="password"/>
                    <div class="fieldDescription">Token for Backend AVDC Server.</div>
                </div>
                <div class="checkboxContainer checkboxContainer-withDescripton">
                    <label class="emby-checkbox-label">
                        <input id="EnableRemoteImageInfo" is="emby-checkbox" name="EnableRemoteImageInfo"
                               type="checkbox"/>
                        <span>Enable Remote Image Info</span>
                    </label>
                </div>
                <div>
                    <button class="raised button-submit block" is="emby-button" type="submit">
                        <span>Save</span></button>
                </div>
            </form>
        </div>
    </div>
    <script type="text/javascript">
        var avdcPluginConfig = {
            uniquePluginId: "001c811c-145d-4b43-94bf-f78e8d7b6afd"
        };

        $('#avdcConfigurationPage').on('pageshow', function () {
            Dashboard.showLoadingMsg();
            ApiClient.getPluginConfiguration(avdcPluginConfig.uniquePluginId).then(function (config) {
                $('#Server').val(config.Server).change();
                $('#Token').val(config.Token).change();
                $('#EnableRemoteImageInfo').prop('checked', config.EnableRemoteImageInfo);
                Dashboard.hideLoadingMsg();
            });
        });

        $('#avdcConfigForm').on('submit', function () {
            Dashboard.showLoadingMsg();
            ApiClient.getPluginConfiguration(avdcPluginConfig.uniquePluginId).then(function (config) {
                config.Server = $('#Server').val();
                config.Token = $('#Token').val();
                config.EnableRemoteImageInfo = $('#EnableRemoteImageInfo').prop('checked');
                ApiClient.updatePluginConfiguration(avdcPluginConfig.uniquePluginId, config).then(Dashboard.processPluginConfigurationUpdateResult);
            });
            return false;
        });
    </script>
</div>
</body>
</html>